<script>
import { checkPosition, checkCooperateEnterprise } from "@/http/api";

export default {
  components: {},
  name: "",
  data() {
    return {
      selectWorkArr: [],
      comArr: [],
      rules: {
        enterprise_position_id: [
          {
            required: true,
            message: "请选择面试的岗位",
            trigger: "change",
          },
        ],
        interview_time: [
          {
            required: true,
            message: "请选择面试日期",
            trigger: "change",
          },
        ],
      },
      formData: {
        enterprise_position_id: "",
        biographical_notes_id: "",
        interview_time: "",
      },
    };
  },
  props: {
    interviewId: {
      type: Number,
      default: "",
    },
  },
  setup() {},
  methods: {
    disPickerTime(time) {
      return time < new Date() - 1000 * 60 * 60 * 24;
    },
    cancelFn() {
      this.$emit("cancel");
    },
    async confirFn() {
      const valid = await this.$refs.ruleForm.validate();
      if (!valid) {
        return;
      }
      let data = { ...this.formData };
      if (data.type == 1) {
        data.interview_enterprise_id = "";
      }
      data.interview_time = this.$converData.getDate(data.interview_time);
      console.log(data);
      this.$emit("ok", data);
    },
    async getWorkData() {
      const { data } = await checkPosition();
      if (data.code == 1) {
        let arr = [];
        if (data.data.length > 0) {
          for (let item of data.data) {
            arr.push({
              label: `${item.position_name}（id:${item.enterprise_position_id}）`,
              value: item.enterprise_position_id,
            });
          }
        }
        this.selectWorkArr = arr;
      }
    },
  },
  mounted() {},
  created() {
    this.formData.biographical_notes_id = this.interviewId;
    this.getWorkData();
  },
};
</script>
<template>
  <div class="dialogMaskCont">
    <el-form label-width="120" :model="formData" :rules="rules" ref="ruleForm">
      <el-form-item prop="enterprise_position_id" label="面试岗位">
        <el-select
          v-model="formData.enterprise_position_id"
          clearable
          filterable
          placeholder="请选择需要备选的岗位"
        >
          <el-option
            v-for="item in selectWorkArr"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item prop="interview_time" label="面试日期">
        <el-date-picker
          v-model="formData.interview_time"
          type="date"
          style="width: 100%"
          :disabled-date="disPickerTime"
          placeholder="请选择面试的具体日期"
        />
      </el-form-item>
    </el-form>
    <el-row class="row-bg" justify="end">
      <el-button @click="cancelFn">取消</el-button>
      <el-button type="primary" @click="confirFn"> 确认 </el-button>
    </el-row>
  </div>
</template>
<style scoped lang="less"></style>
